﻿var selection = new Array();

function previous() {
    history.go(-1);
}

function next() {
    var totalTickets = getCountersTotal();

    if (totalTickets == selection.length) {
        var queryStringSeats = "seats=" + selection[0];

        for (var i = 1; i < selection.length; i++) {
            queryStringSeats += ";" + selection[i];
        }

        window.location("paytickets.aspx?datetime=" + getQueryVariable("datetime") + "&roomnumber=" + getQueryVariable("roomnumber") + "&moviename=" + getQueryVariable("moviename") + "&adultcounter=" + getQueryVariable("adultcounter") + "&childcounter=" + getQueryVariable("childcounter") + "&50pluscounter=" + getQueryVariable("50pluscounter") + "&freecounter=" + getQueryVariable("freecounter") + "&cjpstudentcounter=" + getQueryVariable("cjpstudentcounter") + "&3dglassescounter=" + getQueryVariable("3dglassescounter") + "&" + queryStringSeats);

    } else {
        alert("U moet nog " + (totalTickets - selection.length) + " stoel(en) selecteren.");
    }
}

function seatOnClick(row, seat) {   
    var id = row + "," + seat;
    var element = document.getElementById("row" + row + "seat" + seat);

    switch (element.className) {
        case "free":
            var totalTickets = getCountersTotal();

            if (selection.length < totalTickets) {
                element.className = "selected";
                selection.push(id);
            } else {
                alert("U mag niet meer dan " + totalTickets + " stoelen selecteren.");
            }

            break;
        case "selected":
            element.className = "free";
            selection.splice(selection.indexOf(id), 1);
            break;
    }
}

function getCountersTotal() {
    var adultCount = parseInt(getQueryVariable("adultcounter"));
    var childCount = parseInt(getQueryVariable("childcounter"));
    var fiftyPlusCount = parseInt(getQueryVariable("50pluscounter"));
    var cjpStudentCount = parseInt(getQueryVariable("cjpstudentcounter"));
    var freeCount = parseInt(getQueryVariable("freecounter"));

    return adultCount + childCount + fiftyPlusCount + cjpStudentCount + freeCount;
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}